package com.inmobi.re.controller.util;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.net.Uri;
import com.inmobi.commons.internal.Base64;
import com.inmobi.commons.internal.Log;
import com.inmobi.re.configs.ConfigParams;
import com.inmobi.re.configs.Initializer;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ImageProcessing
{
  public static String convertMediaUriToPath(Uri paramUri, Context paramContext)
  {
    String[] arrayOfString = { "_data" };
    Cursor localCursor = paramContext.getContentResolver().query(paramUri, arrayOfString, null, null, null);
    int i = localCursor.getColumnIndexOrThrow("_data");
    localCursor.moveToFirst();
    String str = localCursor.getString(i);
    localCursor.close();
    return str;
  }

  public static String getBase64EncodedImage(Bitmap paramBitmap, Context paramContext)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    int i = getDefaultImgQuality(paramContext);
    paramBitmap.compress(Bitmap.CompressFormat.JPEG, i, localByteArrayOutputStream);
    return Base64.encodeToString(localByteArrayOutputStream.toByteArray(), 2);
  }

  public static Bitmap getCompressedBitmap(String paramString, Context paramContext)
  {
    try
    {
      int i = getDefaultImgWidth(paramContext) * getDefaultImgHeight(paramContext);
      FileInputStream localFileInputStream1 = new FileInputStream(paramString);
      BitmapFactory.Options localOptions1 = new BitmapFactory.Options();
      localOptions1.inJustDecodeBounds = true;
      BitmapFactory.decodeStream(localFileInputStream1, null, localOptions1);
      localFileInputStream1.close();
      for (int j = 1; localOptions1.outWidth * localOptions1.outHeight * (1.0D / Math.pow(j, 2.0D)) > i; j++);
      FileInputStream localFileInputStream2 = new FileInputStream(paramString);
      Object localObject;
      if (j > 1)
      {
        int k = j - 1;
        BitmapFactory.Options localOptions2 = new BitmapFactory.Options();
        localOptions2.inSampleSize = k;
        Bitmap localBitmap2 = BitmapFactory.decodeStream(localFileInputStream2, null, localOptions2);
        int m = localBitmap2.getHeight();
        int n = localBitmap2.getWidth();
        double d = Math.sqrt(i / (n / m));
        localObject = Bitmap.createScaledBitmap(localBitmap2, (int)(d / m * n), (int)d, true);
        localBitmap2.recycle();
        System.gc();
      }
      while (true)
      {
        localFileInputStream2.close();
        Log.debug("IMRE_3.7.0", "bitmap size - width: " + ((Bitmap)localObject).getWidth() + ", height: " + ((Bitmap)localObject).getHeight());
        return localObject;
        Bitmap localBitmap1 = BitmapFactory.decodeStream(localFileInputStream2);
        localObject = localBitmap1;
      }
    }
    catch (IOException localIOException)
    {
      Log.debug("IMRE_3.7.0", localIOException.getMessage(), localIOException);
    }
    return null;
  }

  public static int getDefaultImgHeight(Context paramContext)
  {
    return Initializer.getConfigParams(paramContext).getPicHeight();
  }

  public static int getDefaultImgQuality(Context paramContext)
  {
    return Initializer.getConfigParams(paramContext).getPicQuality();
  }

  public static int getDefaultImgWidth(Context paramContext)
  {
    return Initializer.getConfigParams(paramContext).getPicWidth();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.re.controller.util.ImageProcessing
 * JD-Core Version:    0.6.2
 */